package com.example.mansystem.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.mansystem.entity.DictDO;
import com.example.mansystem.entity.DictDetailDO;
import com.example.mansystem.mapper.DictDetailMapper;
import com.example.mansystem.mapper.DictMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class DictService extends ServiceImpl<DictMapper, DictDO> {
    @Resource
    DictMapper dictMapper;
    @Resource
    DictDetailMapper dictDetailMapper;
    public Map<String,String> getMapByDictId(int Id)
    {
        LambdaQueryWrapper<DictDetailDO> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DictDetailDO::getDictId,Id);
        List<DictDetailDO> list = dictDetailMapper.selectList(wrapper);
        Map<String,String> res = new HashMap<>();
        for(int i=0;i<list.size();i++)
        {
            res.put(list.get(i).getCode(),list.get(i).getName());
        }
        return res;
    }

    public List<Map<String,String>> getInstrumentCardDict()
    {
        List<Map<String,String>> res=new ArrayList<>();

        res.add(this.getMapByDictId(1));
        res.add(this.getMapByDictId(2));
        res.add(this.getMapByDictId(3));
        res.add(this.getMapByDictId(4));
        res.add(this.getMapByDictId(5));

        return res;
    }
}
